home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 23 / Amiga Format AFCD23 (Feb 1998, Issue 107).iso / +look_here_1st!+ / reader_requests / alienbreed3d2 / cheesesauce / objectmovea < prev    next >
Text File  |  1997-11-28  |  30KB  |  2,150 lines

  1. extlen: dc.w 0
  2. awayfromwall: dc.w 0
  3. wallbounce: dc.w 0
  4. wallxsize: dc.w 0
  5. wallzsize: dc.w 0
  6. walllength: dc.w 0
  7.  
  8. RoomPath: ds.w 100
  9. RoomPathPtr: dc.l 0
  10.  
  11. MoveObject:
  12.  
  13.  move.l #RoomPath,RoomPathPtr
  14.  
  15.  clr.b hitwall
  16.  
  17.  move.w newx,d0
  18.  sub.w oldx,d0
  19.  move.w d0,xdiff
  20.  move.w newz,d0
  21.  sub.w oldz,d0
  22.  move.w d0,zdiff
  23.  
  24.  move.l newy,wallhitheight
  25.  move.l objroom,a0
  26.  
  27. gobackanddoitallagain:
  28.  
  29.  move.l a0,a5
  30.  adda.w ToExitList(a5),a0
  31.  move.l a0,test
  32.  move.l FloorLines,a1
  33. checkwalls:
  34.  move.w (a0)+,d0
  35.  blt nomorewalls
  36.  
  37.  asl.w #4,d0
  38.  lea (a1,d0.w),a2
  39.  
  40. *********************************
  41. * Check if we are within exit limits
  42. * of zone.
  43. *********************************
  44.  
  45.  move.l #-65536*256,d0
  46.  move.l d0,LowerRoofHeight
  47.  move.l d0,UpperRoofHeight
  48.  move.l d0,LowerFloorHeight
  49.  move.l d0,UpperFloorHeight
  50.  
  51. ; tst.b 9(a2)
  52. ; bne thisisawall2
  53.  
  54.  moveq #0,d1
  55.  move.w 8(a2),d1
  56.  blt thisisawall2
  57.  move.l ZoneAdds,a4
  58.  move.l (a4,d1.w*4),a4
  59.  add.l LEVELDATA,a4
  60.  
  61.  move.l ToZoneFloor(a4),d1
  62.  move.l d1,LowerFloorHeight
  63.  move.l ToZoneRoof(a4),d2
  64.  move.l d2,LowerRoofHeight
  65.  sub.l d2,d1
  66.  cmp.l thingheight,d1
  67.  ble thisisawall1
  68.  
  69.  move.l oldy,d0
  70.  move.l d0,d1
  71.  add.l thingheight,d1
  72.  sub.l ToZoneFloor(a4),d1
  73.  bgt.s chkstepup
  74.  
  75.  neg.l d1
  76.  cmp.l StepDownVal,d1
  77.  blt.s botinsidebot
  78.  
  79. chkstepup:
  80.  cmp.l StepUpVal,d1
  81.  blt.s botinsidebot
  82.  
  83. ; We have a wall!
  84.  bra thisisawall1
  85.  
  86. botinsidebot:
  87.  
  88.  sub.l ToZoneRoof(a4),d0
  89.  blt.s thisisawall1
  90.  
  91.  bra checkwalls
  92.  
  93. thisisawall1:
  94.  
  95.  move.l ToUpperFloor(a4),d1
  96.  move.l d1,UpperFloorHeight
  97.  move.l ToUpperRoof(a4),d2
  98.  sub.l d2,d1
  99.  move.l d2,UpperRoofHeight
  100.  cmp.l thingheight,d1
  101.  ble thisisawall2
  102.  
  103.  move.l oldy,d0
  104.  move.l d0,d1
  105.  add.l thingheight,d1
  106.  sub.l ToUpperFloor(a4),d1
  107.  bgt.s chkstepup2
  108.  
  109.  neg.l d1
  110.  cmp.l StepDownVal,d1
  111.  blt.s botinsidebot2
  112.  bra.s thisisawall2
  113.  
  114. chkstepup2:
  115.  cmp.l StepUpVal,d1
  116.  blt.s botinsidebot2
  117.  
  118. ; We have a wall!
  119.  bra thisisawall2
  120.  
  121. botinsidebot2:
  122.  
  123.  sub.l ToUpperRoof(a4),d0
  124.  blt.s thisisawall2
  125.  
  126.  bra checkwalls
  127. thisisawall2
  128.  
  129.  move.l #0,a4
  130.  move.l #0,a6
  131.  move.b awayfromwall,d3
  132.  blt.s .notomatoes
  133.  
  134.  move.b 12(a2),d2
  135.  ext.w d2
  136.  
  137.  move.b 13(a2),d4
  138.  ext.w d4
  139.  
  140.  tst.b d3
  141.  beq.s .noshift
  142.  asl.w d3,d2
  143.  asl.w d3,d4
  144. .noshift
  145.  
  146.  move.w d2,a4
  147.  move.w d4,a6
  148.  
  149. .notomatoes:
  150.  
  151.  move.w newx,d0
  152.  move.w newz,d1
  153.  sub.w (a2),d0
  154.  sub.w 2(a2),d1
  155.  sub.w a4,d0
  156.  sub.w a6,d1
  157.  
  158.  move.w 4(a2),d2
  159.  sub.w a4,d2
  160.  sub.w a6,d2
  161.  
  162.  muls d2,d1
  163.  
  164.  move.w 6(a2),d5
  165.  add.w a4,d5
  166.  sub.w a6,d5
  167.  
  168.  muls d5,d0
  169.  sub.l d1,d0
  170.  blt chkhttt
  171.  
  172.  move.w 10(a2),d3
  173.  add.w extlen,d3
  174.  divs d3,d0
  175.  cmp.w #32,d0
  176.  bge oknothitwall
  177.  
  178.  move.w wallflags(pc),d0
  179.  or.w d0,14(a2) 
  180.  
  181.  bra oknothitwall
  182.  
  183. chkhttt:
  184.  
  185.  move.w d2,WALLXLEN
  186.  move.w d5,WALLZLEN
  187.  
  188.  move.l d0,d7
  189.  
  190.  move.w 10(a2),d3
  191.  add.w extlen,d3
  192.  divs d3,d7    ;  d
  193.  
  194.  move.l newy,d4
  195.  sub.l oldy,d4
  196. ; beq .dontworryhit
  197.  
  198.  move.w oldx,d0
  199.  move.w oldz,d1
  200.  sub.w (a2),d0
  201.  sub.w 2(a2),d1
  202.  sub.w a4,d0
  203.  sub.w a6,d1
  204.  
  205.  muls d2,d1
  206.  muls d5,d0
  207.  sub.l d1,d0
  208.  divs d3,d0    ; otherd
  209.  
  210.  sub.w d7,d0    ; total distance travelled across wall
  211.  bgt.s .ohbugger
  212.  moveq #1,d0
  213. .ohbugger:
  214.  
  215. ; We now have ratio to multiply x,z and y differences
  216. ; by. Check y=0 since that's quite common.
  217.  
  218.  move.l d4,d1
  219.  beq.s .dontworryhit
  220.  
  221.  divs d0,d1
  222.  muls d7,d1
  223. .dontworryhit:
  224.  add.l newy,d1 ; height at point of crossing wall.
  225.  move.l d1,d6
  226.  add.l thingheight,d6
  227.  
  228.  cmp.l LowerFloorHeight,d6
  229.  bge.s .yeshit
  230.  cmp.l LowerRoofHeight,d1
  231.  bgt oknothitwall
  232.  cmp.l UpperRoofHeight,d1
  233.  blt.s .yeshit
  234.  cmp.l UpperFloorHeight,d6
  235.  blt oknothitwall
  236.  
  237. .yeshit:
  238.  
  239.  move.l d1,wallhitheight
  240.  
  241.  tst.b wallbounce
  242.  bne.s .calcbounce
  243.  
  244.  tst.b exitfirst(pc)
  245.  beq.s .calcalong
  246.  bne.s .calcwherehit
  247.  
  248. .calcbounce:
  249.  
  250. ; For simplicity (possibility!) the
  251. ; bounce routine will:
  252. ; Place the object at wall contact
  253. ; point
  254. ; Supply wall data to reflect the
  255. ; movement direction of the object
  256.  
  257.  move.w d2,wallxsize
  258.  move.w d5,wallzsize
  259.  move.w d3,walllength
  260.  
  261. .calcwherehit:
  262.  
  263. ; add.w #20,d7
  264.  move.w newx,d6
  265.  sub.w oldx,d6
  266.  muls d7,d6
  267.  divs d0,d6
  268.  add.w newx,d6
  269.  
  270.  move.w newz,d1
  271.  sub.w oldz,d1
  272.  muls d7,d1
  273.  divs d0,d1
  274.  add.w newz,d1
  275.  move.w d6,d0
  276.  move.w d1,d7
  277.  bra.s .calcedhit
  278.  
  279. .calcalong:
  280.  
  281. ; sub.w #3,d7
  282.  move.w d7,d6
  283.  muls d5,d6
  284.  muls d2,d7
  285.  divs d3,d6
  286.  divs d3,d7
  287.  neg.w d6
  288.  add.w newx,d6    ; point on wall
  289.  add.w newz,d7
  290.  
  291.  move.w d6,d0
  292.  move.w d7,d1
  293. ; bra.s othercheck
  294.  
  295. .calcedhit:
  296.  
  297. ; move.w newx,d6
  298. ; move.w newz,d7
  299. ; sub.w oldx,d6
  300. ; sub.w oldz,d7
  301. ;  
  302. ; move.w (a2),d4
  303. ; add.w a4,d4
  304. ; sub.w oldx,d4
  305. ; muls d4,d7; negative if on left
  306. ; move.w 2(a2),d4
  307. ; add.w a6,d4
  308. ; sub.w oldz,d4
  309. ; muls d4,d6
  310. ; sub.l d6,d7
  311. ; bgt oknothitwall
  312. ;; move.w d0,d6
  313. ;; move.w d1,d7
  314. ; move.w newx,d6
  315. ; move.w newz,d7
  316. ; sub.w oldx,d6
  317. ; sub.w oldz,d7
  318. ; move.w (a2),d4
  319. ; add.w d2,d4
  320. ; sub.w oldx,d4
  321. ; muls d4,d7; negative if on left
  322. ; move.w 2(a2),d4
  323. ; add.w d5,d4
  324. ; sub.w oldz,d4
  325. ; muls d4,d6
  326. ; sub.l d6,d7
  327. ; blt oknothitwall
  328. ; bra hitthewall
  329. ;
  330.  
  331.  move.w (a2),d0
  332.  add.w a4,d0
  333.  sub.w oldx,d0    ; a-e
  334.  move.w newz,d1
  335.  sub.w oldz,d1    ; h-f
  336.  muls d1,d0        ; (a-e)*(h-f)
  337.  
  338.  move.w newx,d2
  339.  sub.w oldx,d2    ; g-e
  340.  
  341.  move.w 2(a2),d3
  342.  add.w a6,d3
  343.  sub.w oldz,d3    ; b-f
  344.  muls d2,d3        ; (g-e)*(b-f)
  345.  sub.l d3,d0        ; (a-e)*(h-f)-(g-e)*(b-f)
  346. ; beq oknothitwall
  347.  
  348.  muls WALLZLEN,d2
  349.  muls WALLXLEN,d1
  350.  sub.l d1,d2
  351.  beq oknothitwall
  352.  
  353.  tst.l d0
  354.  bge.s .toppos
  355.  tst.l d2
  356.  bgt oknothitwall
  357.  cmp.l d0,d2
  358.  bgt oknothitwall
  359.  move.w d6,d0
  360.  move.w d7,d1
  361.  bra hitthewall
  362.  
  363. .toppos
  364.  tst.l d2
  365.  blt oknothitwall
  366.  cmp.l d0,d2
  367.  blt oknothitwall
  368.  move.w d6,d0
  369.  move.w d7,d1
  370.  bra hitthewall
  371.  
  372. othercheck:
  373.  
  374. ; sub.w (a2),d6
  375. ; sub.w 2(a2),d7
  376. ; sub.w a4,d6
  377. ; sub.w a6,d7
  378. ; muls d6,d6
  379. ; muls d7,d7
  380. ; add.w #5,d3
  381. ; muls d3,d3
  382. ; add.l d6,d7
  383. ; cmp.l d3,d7
  384. ; bgt oknothitwall
  385. ; move.w d1,d7
  386. ; move.w d0,d6
  387. ; sub.w (a2),d6
  388. ; sub.w 2(a2),d7
  389. ; sub.w d2,d6
  390. ; sub.w d5,d7
  391. ; muls d6,d6
  392. ; muls d7,d7
  393. ; add.l d6,d7
  394. ; cmp.l d3,d7
  395. ; bgt oknothitwall
  396. ;************8 
  397.  
  398.  sub.w (a2),d6
  399.  sub.w 2(a2),d7
  400.  
  401.  sub.w a4,d6
  402.  sub.w a6,d7
  403.  move.w d2,d4
  404.  bge.s okplus1
  405.  neg.w d4
  406. okplus1
  407.  move.w d5,d3
  408.  bge.s okplus2
  409.  neg.w d3
  410. okplus2:
  411.  cmp.w d4,d3
  412.  bgt.s UseZ
  413.  
  414. ; Use the x coord!
  415.  
  416.  tst.w d6
  417.  bgt.s xispos
  418.  
  419.  move.w d2,d7
  420.  cmp.w #4,d7
  421.  bgt.s oknothitwall
  422.  sub.w #4,d7
  423.  cmp.w d7,d6
  424.  blt.s oknothitwall
  425.  
  426.  bra.s hitthewall
  427.  
  428. xispos:
  429.  
  430.  move.w d2,d7
  431.  cmp.w #-4,d7
  432.  blt.s oknothitwall
  433.  add.w #4,d7
  434.  cmp.w d7,d6
  435.  bgt.s oknothitwall
  436.  
  437.  bra.s hitthewall
  438.  
  439. UseZ:
  440.  tst.w d7
  441.  bgt.s zispos
  442.  
  443.  move.w d5,d6
  444.  cmp.w #4,d6
  445.  bgt.s oknothitwall
  446.  sub.w #4,d6
  447.  cmp.w d6,d7
  448.  blt.s oknothitwall
  449.  
  450.  bra.s hitthewall
  451.  
  452. zispos:
  453.  
  454.  move.w d5,d6
  455.  cmp.w #-4,d6
  456.  blt.s oknothitwall
  457.  add.w #4,d6
  458.  cmp.w d6,d7
  459.  bgt.s oknothitwall 
  460.  
  461. hitthewall:
  462.  
  463.  move.w d0,newx
  464.  move.w d1,newz
  465.  move.w wallflags(pc),d0
  466.  or.w d0,14(a2)
  467.  st hitwall
  468.  tst.b exitfirst(pc)
  469.  bne stopandleave
  470.  
  471. oknothitwall:
  472.  
  473.  bra checkwalls
  474. nomorewalls:
  475.  
  476.  tst.w extlen
  477.  beq NOOTHERWALLSNEEDED
  478.  
  479.  tst.w xdiff
  480.  bne.s notstill
  481.  tst.w zdiff
  482.  bne.s notstill
  483.  move.l objroom,a0
  484.  bra mustbeinsameroom
  485. notstill:
  486.  
  487.  move.l a5,a0
  488.  add.w ToExitList(a0),a0
  489.  
  490. checkotherwalls:
  491.  move.w (a0)+,d0
  492.  bge anotherwalls
  493.  cmp.w #-2,d0
  494.  beq nomoreotherwalls
  495.  bra checkotherwalls
  496.  
  497. anotherwalls:
  498.  
  499.  asl.w #4,d0
  500.  lea (a1,d0.w),a2
  501.  
  502. *********************************
  503. * Check if we are within exit limits
  504. * of zone.
  505. *********************************
  506.  
  507. ; tst.b 9(a2)
  508. ; bne .thisisawall2
  509.  
  510.  moveq #0,d1
  511.  move.w 8(a2),d1
  512.  blt .thisisawall2
  513.  move.l ZoneAdds,a4
  514.  move.l (a4,d1.w*4),a4
  515.  add.l LEVELDATA,a4
  516.  
  517.  move.l ToZoneFloor(a4),d1
  518.  sub.l ToZoneRoof(a4),d1
  519.  cmp.l thingheight,d1
  520.  ble .thisisawall1
  521.  
  522.  move.l newy,d0
  523.  move.l d0,d1
  524.  add.l thingheight,d1
  525.  sub.l ToZoneFloor(a4),d1
  526.  bgt.s .chkstepup
  527.  
  528.  neg.l d1
  529.  cmp.l StepDownVal,d1
  530.  blt.s .botinsidebot
  531.  bra.s .thisisawall1
  532.  
  533. .chkstepup:
  534.  
  535.  cmp.l StepUpVal,d1
  536.  blt.s .botinsidebot
  537.  
  538. ; We have a wall!
  539.  bra .thisisawall1
  540.  
  541. .botinsidebot:
  542.  
  543.  sub.l ToZoneRoof(a4),d0
  544.  blt.s .thisisawall1
  545.  
  546.  bra checkotherwalls
  547.  
  548. .thisisawall1:
  549.  
  550.  move.l ToUpperFloor(a4),d1
  551.  sub.l ToUpperRoof(a4),d1
  552.  cmp.l thingheight,d1
  553.  ble .thisisawall2
  554.  
  555.  move.l newy,d0
  556.  move.l d0,d1
  557.  add.l thingheight,d1
  558.  sub.l ToUpperFloor(a4),d1
  559.  bgt.s .chkstepup2
  560.  
  561.  neg.l d1
  562.  cmp.l StepDownVal,d1
  563.  blt.s .botinsidebot2
  564.  bra.s .thisisawall2
  565.  
  566. .chkstepup2:
  567.  
  568.  cmp.l StepUpVal,d1
  569.  blt.s .botinsidebot2
  570.  
  571. ; We have a wall!
  572.  bra .thisisawall2
  573.  
  574. .botinsidebot2:
  575.  
  576.  sub.l ToUpperRoof(a4),d0
  577.  blt.s .thisisawall2
  578.  
  579.  bra checkotherwalls
  580.  
  581. .thisisawall2:
  582.  
  583.  move.l #0,a4
  584.  move.l #0,a6
  585.  move.b awayfromwall,d3
  586.  blt.s .notomatoes
  587.  
  588.  move.b 12(a2),d2
  589.  ext.w d2
  590.  
  591.  move.b 13(a2),d4
  592.  ext.w d4
  593.  
  594.  tst.b d3
  595.  beq.s .noshift
  596.  asl.w d3,d2
  597.  asl.w d3,d4
  598. .noshift
  599.  
  600.  move.w d2,a4
  601.  move.w d4,a6
  602.  
  603. .notomatoes:
  604.  
  605.  move.w 4(a2),d2
  606.  sub.w a4,d2
  607.  sub.w a6,d2
  608.  move.w d2,DX
  609.  move.w 6(a2),d5
  610.  add.w a4,d5
  611.  sub.w a6,d5
  612.  
  613.  
  614.  move.w newx,d0
  615.  move.w newz,d1
  616.  sub.w (a2),d0
  617.  sub.w 2(a2),d1
  618.  sub.w a4,d0
  619.  sub.w a6,d1
  620.  muls DX,d1
  621.  muls d5,d0
  622.  sub.l d1,d0
  623.  bge .oknothitwall
  624.  move.l d0,d7
  625.  
  626.  move.w oldx,d1
  627.  move.w newx,d3
  628.  sub.w d1,d3
  629.  sub.w (a2),d1
  630.  sub.w a4,d1 ;e-a=d1
  631.  
  632.  move.w 2(a2),d2
  633.  add.w a6,d2
  634.  sub.w oldz,d2    ;b-f=d2
  635.  
  636.  move.w newz,d4
  637.  sub.w oldz,d4
  638.  
  639.  muls d4,d1
  640.  muls d3,d2
  641.  add.l d2,d1    ; h(e-a)+g(b-f)
  642.  
  643.  muls DX,d4
  644.  muls d5,d3
  645.  sub.l d3,d4
  646.  beq .oknothitwall
  647.  bgt.s .botpos
  648. .botneg:
  649.  tst.l d1
  650.  bgt .oknothitwall
  651.  cmp.l d1,d4
  652.  ble .mighthit
  653.  bra .oknothitwall
  654.  
  655. .botpos:
  656.  tst.l d1
  657.  blt .oknothitwall
  658.  cmp.l d1,d4
  659.  blt .oknothitwall
  660.  
  661. .mighthit:
  662.  
  663.  move.w 10(a2),d0
  664.  add.w extlen,d0
  665.  divs d0,d7    ;  d
  666.  sub.w #3,d7
  667.  move.w d7,d6
  668.  muls d5,d6
  669.  muls DX,d7
  670.  divs d0,d6
  671.  divs d0,d7
  672.  neg.w d6
  673.  add.w newx,d6    ; point on wall
  674.  add.w newz,d7
  675.  
  676.  move.w oldx,d0
  677.  move.w oldz,d1
  678.  sub.w (a2),d0
  679.  sub.w 2(a2),d1
  680.  sub.w a4,d0
  681.  sub.w a6,d1
  682.  muls DX,d1
  683.  muls d5,d0
  684.  sub.l d1,d0
  685.  blt .oknothitwall
  686.  
  687.  move.w d6,d0
  688.  move.w d7,d1
  689.  
  690.  bra .hitthewall
  691.  
  692.  sub.w (a2),d6
  693.  sub.w 2(a2),d7
  694.  move.w d6,d4
  695.  bge.s .okplus1
  696.  neg.w d4
  697. .okplus1
  698.  move.w d7,d3
  699.  bge.s .okplus2
  700.  neg.w d3
  701. .okplus2:
  702.  cmp.w d4,d3
  703.  bgt.s .UseZ
  704.  
  705. ; Use the x coord!
  706.  
  707.  tst.w d6
  708.  bgt.s .xispos
  709.  
  710.  move.w DX,d7
  711.  bgt.s .oknothitwall
  712.  cmp.w d7,d6
  713.  blt.s .oknothitwall
  714.  
  715.  bra.s .hitthewall
  716.  
  717. .xispos:
  718.  
  719.  move.w DX,d7
  720.  blt.s .oknothitwall
  721.  cmp.w d7,d6
  722.  bgt.s .oknothitwall
  723.  
  724.  bra.s .hitthewall
  725.  
  726. .UseZ:
  727.  tst.w d7
  728.  bgt.s .zispos
  729.  
  730.  move.w d5,d6
  731.  bgt.s .oknothitwall
  732.  cmp.w d6,d7
  733.  blt.s .oknothitwall
  734.  
  735.  bra.s .hitthewall
  736.  
  737. .zispos:
  738.  
  739.  move.w d5,d6
  740.  blt.s .oknothitwall
  741.  cmp.w d6,d7
  742.  bgt.s .oknothitwall
  743.  
  744.  
  745. .hitthewall:
  746.  
  747.  move.w d0,newx
  748.  move.w d1,newz
  749.  move.w wallflags(pc),d0
  750.  or.w d0,14(a2)
  751.  st hitwall
  752.  tst.b exitfirst(pc)
  753.  bne stopandleave
  754.  
  755. .oknothitwall:
  756.  
  757.  bra checkotherwalls
  758. nomoreotherwalls:
  759.  
  760. NOOTHERWALLSNEEDED
  761.  
  762.  
  763. ; move.w xdiff,d2
  764. ; muls d2,d2
  765. ; move.w zdiff,d3
  766. ; muls d3,d3
  767. ; move.w #0,movespd
  768. ; move.l #0,largespd
  769. ; add.l d3,d2
  770. ;
  771. ; move.w #31,d0
  772. ;.findhigh
  773. ; btst d0,d2
  774. ; bne .foundhigh
  775. ; dbra d0,.findhigh
  776. ;.foundhigh
  777. ; asr.w #1,d0
  778. ; clr.l d3
  779. ; bset d0,d3
  780. ; move.l d3,d0
  781. ;
  782. ; move.w d0,d3
  783. ; muls d3,d3    ; x*x
  784. ; sub.l d2,d3    ; x*x-a
  785. ; asr.l #1,d3    ; (x*x-a)/2
  786. ; divs d0,d3    ; (x*x-a)/2x
  787. ; sub.w d3,d0    ; second approx
  788. ; bgt .stillnot0
  789. ; move.w #1,d0
  790. ;.stillnot0
  791. ;
  792. ; move.w d0,d3
  793. ; muls d3,d3
  794. ; sub.l d2,d3
  795. ; asr.l #1,d3
  796. ; divs d0,d3
  797. ; sub.w d3,d0    ; second approx
  798. ; bgt .stillnot02
  799. ; move.w #1,d0
  800. ;.stillnot02
  801. ;
  802. ; move.w d0,movespd
  803. ;.moving
  804. ; ext.l d0
  805. ; asl.l #5,d0
  806. ; move.l d0,largespd
  807.  
  808. *****************************************************
  809. * FIND ROOM WE'RE STANDING IN ***********************
  810. *****************************************************
  811.  
  812.  move.l a5,a0
  813.  adda.w ToExitList(a5),a0
  814.  
  815.  move.l FloorLines,a1
  816. CheckMoreFloorLines
  817.  move.w (a0)+,d0    ; Either a floor line or -1
  818.  blt NoMoreFloorLines
  819.  asl.w #4,d0
  820.  lea (a1,d0.w),a2
  821.  
  822.  tst.w 8(a2)
  823.  blt.s CheckMoreFloorLines
  824.  
  825.  clr.b CrossIntoTop
  826.  
  827.  moveq #0,d1
  828.  move.w 8(a2),d1
  829.  move.l ZoneAdds,a4
  830.  move.l (a4,d1.w*4),a4
  831.  add.l LEVELDATA,a4
  832.  
  833.  move.l newy,d0
  834.  move.l d0,d1
  835.  add.l thingheight,d1
  836.  
  837.  sub.l ToZoneRoof(a4),d0
  838.  blt.s NOTINLOWER
  839.  
  840.  sub.l ToZoneFloor(a4),d1
  841.  blt.s okthebottom
  842.  
  843.  cmp.l StepUpVal,d1
  844.  bgt.s NOTINLOWER
  845.  
  846. ; move.l ToZoneFloor(a4),d1
  847. ; sub.l thingheight,d1
  848. ; move.l d1,newy
  849.  bra okthebottom
  850.  
  851. NOTINLOWER:
  852.  
  853.  move.l ToZoneRoof(a4),billy
  854.  move.l ToZoneRoof(a4),billy+4
  855.  add.l d0,billy+4
  856.  
  857.  st CrossIntoTop
  858.  move.l newy,d0
  859.  move.l d0,d1
  860.  add.l thingheight,d1
  861.  sub.l ToUpperRoof(a4),d0
  862.  blt CheckMoreFloorLines
  863.  
  864.  sub.l ToUpperFloor(a4),d1
  865.  blt.s okthebottom
  866.  
  867.  cmp.l StepUpVal,d1
  868.  bgt CheckMoreFloorLines
  869.  
  870. ; move.l ToUpperFloor(a4),d1
  871. ; sub.l thingheight,d1
  872. ; move.l d1,newy
  873.  
  874. okthebottom
  875.  
  876.  move.w newx,d0
  877.  move.w newz,d1
  878.  sub.w (a2),d0    ;a
  879.  sub.w 2(a2),d1    ;b
  880.  muls 4(a2),d1
  881.  muls 6(a2),d0
  882.  moveq #0,d3
  883.  move.w 8(a2),d3
  884.  move.l ZoneAdds,a3
  885.  move.l (a3,d3.w*4),a3
  886.  add.l LEVELDATA,a3
  887.  sub.l d1,d0
  888.  bge StillSameSide
  889.  
  890. * Player is now on the left side of this line.
  891. * Where was he before?
  892.  
  893. ; cmp.l a4,a5
  894. ; bne StillSameSide
  895.  
  896. ; move.w oldx,d0
  897. ; move.w oldz,d1
  898. ; sub.w (a2),d0    ;a
  899. ; sub.w 2(a2),d1    ;b
  900. ; muls 4(a2),d1
  901. ; muls 6(a2),d0
  902. ; sub.l d1,d0
  903. ; blt StillSameSide
  904. ; bra checkifcrossed
  905.  
  906. OnRightsideofline:
  907. * Player is now on the right side of the line.
  908. * Where was he last time?
  909.  
  910. ; exg a3,a4
  911.  
  912. ; cmp.l a3,a5
  913. ; bne StillSameSide
  914.  
  915. ; move.w oldx,d0
  916. ; move.w oldz,d1
  917. ; sub.w (a2),d0    ;a
  918. ; sub.w 2(a2),d1    ;b
  919. ; muls 4(a2),d1
  920. ; muls 6(a2),d0
  921. ; sub.l d1,d0
  922. ; bgt StillSameSide
  923.  
  924. checkifcrossed:
  925.  
  926. *Player used to be on other side of this line.
  927. *Need to check if he crossed it.
  928.  
  929.  move.w (a2),d0
  930.  sub.w oldx,d0    ; a-e
  931.  move.w newz,d1
  932.  sub.w oldz,d1    ; h-f
  933.  muls d1,d0        ; (a-e)*(h-f)
  934.  
  935.  move.w newx,d2
  936.  sub.w oldx,d2    ; g-e
  937.  
  938.  move.w 2(a2),d3
  939.  sub.w oldz,d3    ; b-f
  940.  muls d2,d3        ; (g-e)*(b-f)
  941.  sub.l d3,d0        ; (a-e)*(h-f)-(g-e)*(b-f)
  942.  beq StillSameSide
  943.  
  944.  muls 6(a2),d2
  945.  muls 4(a2),d1
  946.  sub.l d1,d2
  947.  beq StillSameSide
  948.  
  949.  tst.l d0
  950.  bge.s .toppos
  951.  tst.l d2
  952.  bgt.s StillSameSide
  953.  cmp.l d0,d2
  954.  bgt.s StillSameSide
  955.  move.l a3,a5
  956.  move.l RoomPathPtr,a0
  957.  move.w (a3),(a0)+
  958.  move.l a0,RoomPathPtr
  959.  move.l a3,a0
  960.  move.b CrossIntoTop,StoodInTop
  961.  
  962.  
  963.  bra gobackanddoitallagain
  964.  bra.s donefloorline
  965.  
  966. .toppos
  967.  tst.l d2
  968.  blt.s StillSameSide
  969.  cmp.l d0,d2
  970.  blt.s StillSameSide
  971.  move.l a3,a5
  972.  move.l RoomPathPtr,a0
  973.  move.w (a3),(a0)+
  974.  move.l a0,RoomPathPtr
  975.  move.l a3,a0
  976.  move.b CrossIntoTop,StoodInTop
  977.  bra gobackanddoitallagain
  978.  
  979. StillSameSide:
  980. donefloorline:
  981.  
  982.  bra CheckMoreFloorLines
  983. NoMoreFloorLines:
  984.  
  985.  move.l a5,a0
  986.  move.l a5,objroom
  987.  
  988. mustbeinsameroom:
  989.  
  990. stopandleave:
  991.  
  992.  move.l RoomPathPtr,a0
  993.  move.w #-1,(a0)+
  994.  
  995.  rts
  996.  
  997.  
  998. DX: dc.w 0
  999.  
  1000. tstxval: dc.l 0
  1001. oldx: dc.l 0
  1002. oldz: dc.l 0
  1003. newx: dc.l 0
  1004. newz: dc.l 0
  1005. xdiff: dc.l 0
  1006. zdiff: dc.l 0
  1007. objroom: dc.l 0
  1008. hitwall: dc.b 0
  1009. exitfirst: dc.b 0
  1010. speed: dc.w 0
  1011. wallflags: dc.w 0
  1012. distaway: dc.w 0
  1013. newy: dc.l 0
  1014. oldy: dc.l 0
  1015. thingheight: dc.l 0
  1016. StepUpVal: dc.l 0
  1017. StepDownVal: dc.l 0
  1018. wallhitheight: dc.l 0
  1019. seclot: dc.b 0
  1020.  
  1021.  even
  1022. WALLXLEN: dc.w 0
  1023. WALLZLEN: dc.w 0
  1024. onwallx: dc.w 0
  1025. onwallz: dc.w 0
  1026. slidex: dc.w 0
  1027. slidez: dc.w 0
  1028. CrossIntoTop: dc.b 0
  1029. StoodInTop: dc.b 0
  1030. LowerFloorHeight: dc.l 0
  1031. LowerRoofHeight: dc.l 0
  1032. UpperFloorHeight: dc.l 0
  1033. UpperRoofHeight: dc.l 0
  1034.  
  1035. billy: dc.l 0,0
  1036.  
  1037.  even
  1038.  
  1039. HeadTowards:
  1040.  
  1041.  move.w newx,d1
  1042.  sub.w oldx,d1
  1043.  move.w d1,xdiff
  1044.  move.w newz,d2
  1045.  sub.w oldz,d2
  1046.  move.w d2,zdiff
  1047.  muls d1,d1
  1048.  muls d2,d2
  1049.  move.w #0,d0
  1050.  move.w d0,distaway
  1051.  add.l d1,d2
  1052.  beq nochange
  1053.  
  1054.  move.w #31,d0
  1055. .findhigh
  1056.  btst d0,d2
  1057.  bne .foundhigh
  1058.  dbra d0,.findhigh
  1059. .foundhigh
  1060.  asr.w #1,d0
  1061.  clr.l d3
  1062.  bset d0,d3
  1063.  move.l d3,d0
  1064.  
  1065.  move.w d0,d1
  1066.  muls d1,d1    ; x*x
  1067.  sub.l d2,d1    ; x*x-a
  1068.  asr.l #1,d1    ; (x*x-a)/2
  1069.  divs d0,d1    ; (x*x-a)/2x
  1070.  sub.w d1,d0    ; second approx
  1071.  bgt .stillnot0
  1072.  move.w #1,d0
  1073. .stillnot0
  1074.  
  1075.  move.w d0,d1
  1076.  muls d1,d1
  1077.  sub.l d2,d1
  1078.  asr.l #1,d1
  1079.  divs d0,d1
  1080.  sub.w d1,d0    ; second approx
  1081.  bgt .stillnot02
  1082.  move.w #1,d0
  1083. .stillnot02
  1084.  
  1085.  move.w d0,distaway
  1086.  
  1087. ; d0=perpdist
  1088.  
  1089.  cmp.w Range,d0
  1090.  sle GotThere
  1091.  bgt.s faraway
  1092.  
  1093.  move.w xdiff,d1
  1094.  move.w zdiff,d2
  1095.  muls Range,d1
  1096.  muls Range,d2
  1097.  divs d0,d1
  1098.  divs d0,d2
  1099.  neg.w d1
  1100.  neg.w d2
  1101.  add.w d1,newx
  1102.  add.w d2,newz
  1103.  tst.b canshove
  1104.  beq nochange
  1105.  move.w PLR1_opushx(pc),d1
  1106.  add.w PLR2_opushx(pc),d1
  1107.  sub.w d1,newx
  1108.  move.w PLR1_opushz(pc),d1
  1109.  add.w PLR2_opushz(pc),d1
  1110.  sub.w d1,newz
  1111.  move.w xdiff,d1
  1112.  move.w zdiff,d2
  1113.  move.w Range,d3
  1114.  sub.w d0,d3
  1115.  muls d3,d1
  1116.  muls d3,d2
  1117.  divs d0,d1
  1118.  divs d0,d2
  1119.  move.w d1,shovex
  1120.  move.w d2,shovez
  1121.  bra nochange
  1122.  
  1123. faraway:
  1124.  move.w speed,d3
  1125.  add.w Range,d3
  1126.  cmp.w d0,d3
  1127.  blt.s .notoofast
  1128.  move.w d0,d3
  1129.  st GotThere
  1130. .notoofast:
  1131.  sub.w Range,d3
  1132.  
  1133.  move.w xdiff,d1
  1134.  muls d3,d1
  1135.  divs d0,d1
  1136.  move.w zdiff,d2
  1137.  muls d3,d2
  1138.  divs d0,d2
  1139.  add.w oldx,d1
  1140.  move.w d1,newx
  1141.  add.w oldz,d2
  1142.  move.w d2,newz
  1143.  
  1144. nochange:
  1145.  
  1146.  rts
  1147.  
  1148.  
  1149. CalcDist:
  1150.  
  1151.  move.w newx,d1
  1152.  sub.w oldx,d1
  1153.  move.w d1,xdiff
  1154.  move.w newz,d2
  1155.  sub.w oldz,d2
  1156.  move.w d2,zdiff
  1157.  muls d1,d1
  1158.  muls d2,d2
  1159.  move.w #0,d0
  1160.  move.w d0,distaway
  1161.  add.l d1,d2
  1162.  beq .nochange
  1163.  
  1164.  move.w #31,d0
  1165. .findhigh
  1166.  btst d0,d2
  1167.  bne .foundhigh
  1168.  dbra d0,.findhigh
  1169. .foundhigh
  1170.  asr.w #1,d0
  1171.  clr.l d3
  1172.  bset d0,d3
  1173.  move.l d3,d0
  1174.  
  1175.  move.w d0,d1
  1176.  muls d1,d1    ; x*x
  1177.  sub.l d2,d1    ; x*x-a
  1178.  asr.l #1,d1    ; (x*x-a)/2
  1179.  divs d0,d1    ; (x*x-a)/2x
  1180.  sub.w d1,d0    ; second approx
  1181.  bgt .stillnot0
  1182.  move.w #1,d0
  1183. .stillnot0
  1184.  
  1185.  move.w d0,d1
  1186.  muls d1,d1
  1187.  sub.l d2,d1
  1188.  asr.l #1,d1
  1189.  divs d0,d1
  1190.  sub.w d1,d0    ; second approx
  1191.  bgt .stillnot02
  1192.  move.w #1,d0
  1193. .stillnot02
  1194.  
  1195.  move.w d0,distaway
  1196. .nochange:
  1197.  
  1198.  rts
  1199.  
  1200.  
  1201. counterer: dc.w 0
  1202. CosRet: dc.w 0
  1203. SinRet: dc.w 0
  1204.  
  1205. HeadTowardsAng:
  1206.  
  1207.  move.w newx,d1
  1208.  sub.w oldx,d1
  1209.  move.w d1,xdiff
  1210.  move.w newz,d2
  1211.  sub.w oldz,d2
  1212.  move.w d2,zdiff
  1213.  muls d1,d1
  1214.  muls d2,d2
  1215.  move.w #0,d0
  1216.  add.l d1,d2
  1217.  seq GotThere
  1218.  beq .nochange
  1219.  
  1220.  move.w #31,d0
  1221. .findhigh
  1222.  btst d0,d2
  1223.  bne .foundhigh
  1224.  dbra d0,.findhigh
  1225. .foundhigh
  1226.  asr.w #1,d0
  1227.  clr.l d3
  1228.  bset d0,d3
  1229.  move.l d3,d0
  1230.  
  1231.  move.w d0,d1
  1232.  muls d1,d1    ; x*x
  1233.  sub.l d2,d1    ; x*x-a
  1234.  asr.l #1,d1    ; (x*x-a)/2
  1235.  divs d0,d1    ; (x*x-a)/2x
  1236.  sub.w d1,d0    ; second approx
  1237.  bgt .stillnot0
  1238.  move.w #1,d0
  1239. .stillnot0
  1240.  
  1241.  move.w d0,d1
  1242.  muls d1,d1
  1243.  sub.l d2,d1
  1244.  asr.l #1,d1
  1245.  divs d0,d1
  1246.  sub.w d1,d0    ; second approx
  1247.  bgt .stillnot02
  1248.  move.w #1,d0
  1249. .stillnot02
  1250.  
  1251.  move.w d0,d1
  1252.  muls d1,d1
  1253.  sub.l d2,d1
  1254.  asr.l #1,d1
  1255.  divs d0,d1
  1256.  sub.w d1,d0    ; second approx
  1257.  bgt .stillnot03
  1258.  move.w #1,d0
  1259. .stillnot03
  1260.  
  1261.  
  1262. ; d0=perpdist
  1263.  
  1264.  cmp.w Range,d0
  1265.  sle GotThere
  1266.  bgt .faraway
  1267.  
  1268.  move.w oldx,newx
  1269.  move.w oldz,newz
  1270.  bra .nochange
  1271.  
  1272.  move.w xdiff,d1
  1273.  move.w zdiff,d2
  1274.  muls Range,d1
  1275.  muls Range,d2
  1276.  addq #3,d0
  1277.  divs d0,d1
  1278.  divs d0,d2
  1279.  subq #3,d0
  1280.  neg.w d1
  1281.  neg.w d2
  1282.  add.w d1,newx
  1283.  add.w d2,newz
  1284.  tst.b canshove
  1285.  beq .nochange
  1286.  move.w PLR1_opushx(pc),d1
  1287.  add.w PLR2_opushx(pc),d1
  1288.  sub.w d1,newx
  1289.  move.w PLR1_opushz(pc),d1
  1290.  add.w PLR2_opushz(pc),d1
  1291.  sub.w d1,newz
  1292.  move.w xdiff,d1
  1293.  move.w zdiff,d2
  1294.  move.w Range,d3
  1295.  sub.w d0,d3
  1296.  muls d3,d1
  1297.  muls d3,d2
  1298.  divs d0,d1
  1299.  divs d0,d2
  1300.  move.w d1,shovex
  1301.  move.w d2,shovez
  1302.  bra .nochange
  1303.  
  1304. .faraway:
  1305.  
  1306.  move.w speed,d3
  1307.  add.w Range,d3
  1308.  cmp.w d0,d3
  1309.  blt.s .notoofast
  1310.  move.w d0,d3
  1311.  st GotThere
  1312. .notoofast:
  1313.  sub.w Range,d3
  1314.  
  1315.  move.w xdiff,d1
  1316.  muls d3,d1
  1317.  divs d0,d1
  1318.  move.w zdiff,d2
  1319.  muls d3,d2
  1320.  divs d0,d2
  1321.  add.w oldx,d1
  1322.  move.w d1,newx
  1323.  add.w oldz,d2
  1324.  move.w d2,newz
  1325.  
  1326. .nochange:
  1327.  
  1328.  tst.w d0
  1329.  beq.s nocossin
  1330.  
  1331.  add.w #1,d0
  1332.  move.w xdiff,d1
  1333.  swap d1
  1334.  clr.w d1
  1335.  asr.l #1,d1
  1336.  divs d0,d1
  1337.  move.w d1,SinRet
  1338.  move.w zdiff,d1
  1339.  swap d1
  1340.  clr.w d1
  1341.  asr.l #1,d1
  1342.  divs d0,d1
  1343.  move.w d1,CosRet
  1344.  
  1345.  move.w SinRet,d0
  1346.  move.w #0,d2
  1347.  move.l #SineTable,a2
  1348.  lea 2048(a2),a3
  1349.  move.w #3,d5
  1350.  move.w #2048,d6
  1351. findanglop:
  1352.  
  1353.  move.w (a2,d2.w*2),d3
  1354.  move.w (a3,d2.w*2),d4
  1355.  muls d0,d4
  1356.  muls d1,d3
  1357.  sub.l d3,d4
  1358.  blt.s subang
  1359.  add.w d6,d2
  1360.  add.w d6,d2
  1361. subang:
  1362.  sub.w d6,d2
  1363.  and.w #4095,d2
  1364.  asr.w #1,d6
  1365.  dbra d5,findanglop
  1366.  add.w d2,d2
  1367.  move.w d2,AngRet
  1368.  
  1369. nocossin:
  1370.  
  1371.  rts
  1372.  
  1373. AngRet: dc.w 0
  1374. Range: dc.w 0
  1375. GotThere: dc.w 0
  1376. shovex: dc.w 0
  1377. shovez: dc.w 0
  1378. canshove: dc.w 0
  1379. PLR2_pushx: dc.l 0
  1380. PLR2_pushz: dc.l 0
  1381. PLR2_opushx: dc.l 0
  1382. PLR2_opushz: dc.l 0
  1383. PLR1_pushx: dc.l 0
  1384. PLR1_pushz: dc.l 0
  1385. PLR1_opushx: dc.l 0
  1386. PLR1_opushz: dc.l 0
  1387.  
  1388. CheckHit:
  1389.  move.w newx,d0
  1390.  sub.w oldx,d0
  1391.  move.w newz,d1
  1392.  sub.w oldz,d1
  1393.  muls d1,d1
  1394.  muls d0,d0
  1395.  add.l d0,d1
  1396.  cmp.l d2,d1
  1397.  slt hitwall
  1398.  rts
  1399.  
  1400. GetNextCPt:
  1401.  cmp.w d0,d1
  1402.  beq.s noneedforhassle
  1403.  muls #100,d0
  1404.  ext.l d1
  1405.  add.l d1,d0
  1406.  move.l a0,-(a7)
  1407.  lea ControlPts,a0
  1408.  move.b (a0,d0.w),d0
  1409.  ext.w d0
  1410.  move.l (a7)+,a0
  1411. noneedforhassle:
  1412.  rts
  1413.  
  1414. FromRoom: dc.l 0
  1415. ToRoom: dc.l 0
  1416. CanSee: dc.w 0
  1417. Facedir: dc.w 0
  1418.  
  1419.  even
  1420.  
  1421. CanItBeSeenAng:
  1422.  movem.l d0-d7/a0-a6,-(a7)
  1423.  
  1424.  move.w Facedir,d0
  1425.  move.l #SineTable,a0
  1426.  add.w d0,a0
  1427.  move.w (a0),d0
  1428.  move.w 2048(a0),d1
  1429.  move.w Targetx,d2
  1430.  sub.w Viewerx,d2
  1431.  move.w Targetz,d3
  1432.  sub.w Viewerz,d3
  1433.  muls d1,d2
  1434.  muls d0,d3
  1435.  sub.l d3,d2
  1436.  bgt.s ItMightBeSeen
  1437.  clr.b CanSee
  1438.  movem.l (a7)+,d0-a7/a0-a6
  1439.  rts
  1440. ItMightBeSeen:
  1441.  
  1442.  move.l ToRoom,a0
  1443.  move.w (a0),d0
  1444.  move.l FromRoom,a0
  1445.  adda.w #ToListOfGraph,a0
  1446.  bra.s InList
  1447.  
  1448. Viewerx: dc.l 0
  1449. Viewerz: dc.l 0
  1450. Targetx: dc.l 0
  1451. Targetz: dc.l 0
  1452. ViewerTop: dc.b 0
  1453. TargetTop: dc.b 0 
  1454. Viewery: dc.w 0
  1455. Targety: dc.w 0
  1456.  
  1457.   even
  1458.  
  1459. insameroom:
  1460.  st CanSee
  1461.  move.b ViewerTop,d0
  1462.  move.b TargetTop,d1
  1463.  eor.b d0,d1
  1464.  bne outlist
  1465.  movem.l (a7)+,d0-d7/a0-a6
  1466.  rts
  1467.  
  1468. CanItBeSeen:
  1469.  
  1470.  movem.l d0-d7/a0-a6,-(a7)
  1471.  move.l ToRoom,a1
  1472.  move.w (a1),d0
  1473.  move.l FromRoom,a0
  1474.  cmp.l a0,a1
  1475.  beq.s insameroom
  1476.  
  1477.  adda.w #ToListOfGraph,a0
  1478.  
  1479. InList:
  1480.  move.w (a0),d1
  1481.  tst.w d1
  1482.  blt outlist
  1483.  move.l ZoneGraphAdds,a1
  1484.  move.l (a1,d1.w*8),a1
  1485.  add.l LEVELGRAPHICS,a1
  1486.  
  1487.  adda.w #8,a0
  1488.  cmp.w (a1),d0
  1489.  beq isinlist
  1490.  
  1491.  bra.s InList
  1492.  
  1493. isinlist:
  1494. ; We have found the dest room in the
  1495. ; list of rooms visible from the
  1496. ; source room.
  1497.  
  1498. ; Do line of sight!
  1499.  
  1500.  st CanSee
  1501.  
  1502.  move.l Points,a2
  1503.  move.w Targetx,d1
  1504.  move.w Targetz,d2
  1505.  sub.w Viewerx,d1
  1506.  sub.w Viewerz,d2
  1507.  
  1508.  moveq #0,d3
  1509.  move.w -6(a0),d3
  1510.  blt nomorerclips
  1511.  move.l LEVELCLIPS,a1
  1512.  lea (a1,d3.l*2),a1
  1513.  move.l a1,clipstocheck
  1514. checklcliploop:
  1515.  tst.w (a1)
  1516.  blt nomorelclips
  1517.  
  1518.  move.w (a1),d0
  1519.  blt.s noleftone
  1520.  move.l (a2,d0.w*4),d3
  1521.  move.w d3,d4
  1522.  sub.w Viewerz,d4
  1523.  swap d3
  1524.  sub.w Viewerx,d3
  1525.  muls d2,d3
  1526.  muls d1,d4
  1527.  sub.l d3,d4
  1528.  ble outlist
  1529.  
  1530. noleftone:
  1531.  
  1532.  addq #2,a1
  1533.  
  1534.  bra checklcliploop
  1535.  
  1536. nomorelclips:
  1537.  
  1538.  addq #2,a1
  1539.  
  1540. checkrcliploop:
  1541.  tst.w (a1)
  1542.  blt nomorerclips
  1543.  
  1544.  move.w (a1),d0
  1545.  blt.s norightone
  1546.  move.l (a2,d0.w*4),d3
  1547.  move.w d3,d4
  1548.  sub.w Viewerz,d4
  1549.  swap d3
  1550.  sub.w Viewerx,d3
  1551.  muls d2,d3
  1552.  muls d1,d4
  1553.  sub.l d3,d4
  1554.  bge outlist
  1555.  
  1556. norightone:
  1557.  addq #2,a1
  1558.  
  1559.  bra checkrcliploop
  1560.  
  1561.  
  1562. nomorerclips:
  1563.  
  1564. ; No clipping points in the way; got to do the
  1565. ; vertical working out now.
  1566.  
  1567.  move.w Targetx,d0
  1568.  move.w Targetz,d1
  1569.  sub.w Viewerx,d0
  1570.  sub.w Viewerz,d1
  1571.  move.l FromRoom,a5
  1572.  move.l FloorLines,a1
  1573.  move.b ViewerTop,d2
  1574.  move.w Targety,d7
  1575.  sub.w Viewery,d7
  1576.  
  1577.  
  1578. GoThroughZones:
  1579.  move.l a5,a0
  1580.  adda.w ToExitList(a0),a0
  1581.  
  1582. FindWayOut:
  1583.  move.w (a0)+,d5
  1584.  blt outlist
  1585.  asl.w #4,d5
  1586.  lea (a1,d5.w),a2
  1587.  
  1588.  move.w (a2),d3
  1589.  move.w 2(a2),d4
  1590.  sub.w Viewerx,d3
  1591.  sub.w Viewerz,d4
  1592.  move.w d3,d5
  1593.  move.w d4,d6
  1594.  muls d1,d3
  1595.  muls d0,d4
  1596.  sub.l d3,d4
  1597.  ble FindWayOut
  1598.  
  1599.  add.w 4(a2),d5
  1600.  add.w 6(a2),d6
  1601.  muls d0,d6
  1602.  muls d1,d5
  1603.  sub.l d5,d6
  1604.  bge FindWayOut
  1605.  
  1606.  tst.w 8(a2)
  1607.  blt outlist
  1608.  
  1609. ; Here is the exit from the room. Calculate the height at which
  1610. ; we meet it.
  1611.  
  1612.  move.w Targetx,d3
  1613.  move.w Targetz,d4
  1614.  sub.w (a2),d3
  1615.  sub.w 2(a2),d4
  1616.  muls 4(a2),d4
  1617.  muls 6(a2),d3
  1618.  sub.l d3,d4    ; positive
  1619.  
  1620.  move.w Viewerx,d5
  1621.  move.w Viewerz,d6
  1622.  sub.w (a2),d5
  1623.  sub.w 2(a2),d6
  1624.  muls 4(a2),d6
  1625.  muls 6(a2),d5
  1626.  sub.l d6,d5    ; positive
  1627.  
  1628.  divs 10(a2),d4
  1629.  divs 10(a2),d5
  1630.  
  1631.  add.w d5,d4
  1632.  beq.s sameheight
  1633.  muls d7,d5
  1634.  divs d4,d5
  1635. sameheight:
  1636.  add.w Viewery,d5    ; height at which we cross wall
  1637.  
  1638.  ext.l d5
  1639.  asl.l #7,d5
  1640.  
  1641.  tst.b d2
  1642.  beq.s comparewithbottom
  1643.  
  1644.  cmp.l ToUpperRoof(a5),d5
  1645.  blt outlist
  1646.  cmp.l ToUpperFloor(a5),d5
  1647.  bgt outlist
  1648.  bra.s madeit
  1649.  
  1650. comparewithbottom:
  1651.  cmp.l ToZoneRoof(a5),d5
  1652.  blt outlist
  1653.  cmp.l ToZoneFloor(a5),d5
  1654.  bgt outlist
  1655. madeit:
  1656.  st donessomething
  1657.  
  1658.  moveq #0,d3
  1659.  move.w 8(a2),d3
  1660.  move.l ZoneAdds,a3
  1661.  move.l (a3,d3.w*4),a5
  1662.  add.l LEVELDATA,a5
  1663.  
  1664.  clr.b d2
  1665.  cmp.l ToZoneFloor(a5),d5
  1666.  bgt outlist
  1667.  cmp.l ToZoneRoof(a5),d5
  1668.  bgt.s GotIn
  1669.  st d2
  1670.  cmp.l ToUpperFloor(a5),d5
  1671.  bgt outlist
  1672.  cmp.l ToUpperRoof(a5),d5
  1673.  blt outlist
  1674.  
  1675. GotIn:
  1676.  
  1677.  cmp.l ToRoom,a5
  1678.  bne GoThroughZones
  1679.  
  1680.  move.b TargetTop,d3
  1681.  eor.b d2,d3
  1682.  bne outlist
  1683.  
  1684.  movem.l (a7)+,d0-d7/a0-a6
  1685.  rts
  1686.  
  1687. clipstocheck: dc.l 0
  1688. donessomething: dc.w 0
  1689.  
  1690. outlist:
  1691.  clr.b CanSee
  1692.  movem.l (a7)+,d0-d7/a0-a6
  1693.  rts
  1694.  
  1695.  
  1696. FindCollisionPt:
  1697.  movem.l d0-a7/a0-a6,-(a7)
  1698.  
  1699.  move.w Targetx,d0
  1700.  move.w Targetz,d1
  1701.  sub.w Viewerx,d0
  1702.  sub.w Viewerz,d1
  1703.  move.l FromRoom,a5
  1704.  move.l FloorLines,a1
  1705.  move.b ViewerTop,d2
  1706.  move.w Targety,d7
  1707.  sub.w Viewery,d7
  1708.  
  1709.  
  1710. .GoThroughZones:
  1711.  move.l a5,a0
  1712.  adda.w ToExitList(a0),a0
  1713.  
  1714. .FindWayOut:
  1715.  move.w (a0)+,d5
  1716.  blt outlist
  1717.  asl.w #4,d5
  1718.  lea (a1,d5.w),a2
  1719.  
  1720.  move.w (a2),d3
  1721.  move.w 2(a2),d4
  1722.  sub.w Viewerx,d3
  1723.  sub.w Viewerz,d4
  1724.  move.w d3,d5
  1725.  move.w d4,d6
  1726.  muls d1,d3
  1727.  muls d0,d4
  1728.  sub.l d3,d4
  1729.  ble .FindWayOut
  1730.  
  1731.  add.w 4(a2),d5
  1732.  add.w 6(a2),d6
  1733.  muls d0,d6
  1734.  muls d1,d5
  1735.  sub.l d5,d6
  1736.  bge .FindWayOut
  1737.  
  1738.  
  1739. ; Here is the exit from the room. Calculate the height at which
  1740. ; we meet it.
  1741.  
  1742.  move.w Targetx,d3
  1743.  move.w Targetz,d4
  1744.  sub.w (a2),d3
  1745.  sub.w 2(a2),d4
  1746.  muls 4(a2),d4
  1747.  muls 6(a2),d3
  1748.  sub.l d3,d4    ; positive
  1749.  
  1750.  move.w Viewerx,d5
  1751.  move.w Viewerz,d6
  1752.  sub.w (a2),d5
  1753.  sub.w 2(a2),d6
  1754.  muls 4(a2),d6
  1755.  muls 6(a2),d5
  1756.  sub.l d6,d5    ; positive
  1757.  
  1758.  divs 10(a2),d4
  1759.  divs 10(a2),d5
  1760.  
  1761.  move.w d5,d6
  1762.  add.w d5,d4
  1763.  beq.s .sameheight
  1764.  muls d7,d5
  1765.  divs d4,d5
  1766. .sameheight:
  1767.  add.w Viewery,d5    ; height at which we cross wall
  1768.  
  1769.  ext.l d5
  1770.  asl.l #7,d5
  1771.  
  1772.  moveq #0,d3
  1773.  move.w 8(a2),d3
  1774.  blt foundpt
  1775.  move.l ZoneAdds,a3
  1776.  move.l (a3,d3.w*4),a5
  1777.  add.l LEVELDATA,a5
  1778.  
  1779.  clr.b d2
  1780.  cmp.l ToZoneFloor(a5),d5
  1781.  bgt foundpt
  1782.  cmp.l ToZoneRoof(a5),d5
  1783.  bgt.s .GotIn
  1784.  st d2
  1785.  cmp.l ToUpperFloor(a5),d5
  1786.  bgt foundpt
  1787.  cmp.l ToUpperRoof(a5),d5
  1788.  blt foundpt
  1789.  
  1790. .GotIn:
  1791.  
  1792.  bra .GoThroughZones
  1793.  
  1794.  tst.w d4
  1795.  beq.s foundpt
  1796.  muls d6,d0
  1797.  divs d4,d0
  1798.  muls d6,d1
  1799.  divs d4,d1
  1800.  add.w Viewerx,d0
  1801.  add.w Viewerz,d1
  1802.  move.w d0,Targetx
  1803.  move.w d1,Targetz
  1804.  move.l d5,Targety
  1805.  
  1806. foundpt:
  1807.  
  1808.  movem.l (a7)+,d0-a7/a0-a6
  1809.  rts
  1810.  
  1811. GetRand:
  1812.  move.w Rand1,d0
  1813.  add.w #29,d0
  1814.  eor.w #$5f37,d0
  1815.  neg.w d0
  1816.  rol.w #5,d0
  1817.  move.w d0,Rand1
  1818.  rts
  1819.  
  1820. Rand1: dc.w 234
  1821.  
  1822. GoInDirection:
  1823.  move.l #SineTable,a0
  1824.  lea (a0,d0.w),a0
  1825.  move.w (a0),d1
  1826.  move.w 2048(a0),d2
  1827.  muls speed,d1
  1828.  add.l d1,d1
  1829.  muls speed,d2
  1830.  add.l d2,d2
  1831.  swap d1
  1832.  swap d2
  1833.  add.w oldx,d1
  1834.  add.w oldz,d2
  1835.  move.w d1,newx
  1836.  move.w d2,newz
  1837.  rts
  1838.  
  1839. CollideFlags: dc.l 0
  1840.  
  1841. Collision:
  1842.  
  1843.  move.l ObjectData,a0
  1844.  move.w CollId,d0
  1845.  asl.w #6,d0
  1846.  move.b 16(a0,d0.w),d0
  1847.  ext.w d0
  1848.  
  1849.  sub.w #64,a0
  1850.  move.l ObjectPoints,a1
  1851.  move.l #ColBoxTable,a2
  1852.  lea  (a2,d0.w*8),a3
  1853.  
  1854.  move.l CollideFlags,d7
  1855.  move.b StoodInTop,d6
  1856.  move.l newy,d4
  1857.  move.l d4,d5
  1858.  add.l thingheight,d5
  1859.  asr.l #7,d4
  1860.  asr.l #7,d5
  1861.  clr.b hitwall
  1862.  
  1863. checkcol:
  1864.  add.w #64,a0
  1865.  
  1866.  move.w (a0),d0
  1867.  blt checkedallcol
  1868.  
  1869.  cmp.w CollId,d0
  1870.  beq.s checkcol
  1871.  
  1872.  tst.w 12(a0)
  1873.  blt.s checkcol
  1874.  
  1875.  tst.b numlives(a0)
  1876.  beq.s checkcol
  1877.  
  1878.  move.b ObjInTop(a0),d1
  1879.  eor.b d6,d1
  1880.  bne checkcol
  1881.  
  1882.  moveq #0,d3
  1883.  move.b 16(a0),d3
  1884.  blt checkcol
  1885.  
  1886.  btst d3,d7
  1887.  beq checkcol
  1888.  
  1889.  move.w 4(a0),d1
  1890.  sub.w 2(a2,d3.w*8),d1
  1891.  cmp.w d1,d5
  1892.  blt checkcol
  1893.  add.w 4(a2,d3.w*8),d1
  1894.  cmp.w d1,d4
  1895.  bgt checkcol
  1896.  
  1897.  move.w (a1,d0.w*8),d1
  1898.  move.w 4(a1,d0.w*8),d2
  1899.  sub.w newx,d1
  1900.  bge.s .xnoneg
  1901.  neg.w d1
  1902. .xnoneg:
  1903.  sub.w newz,d2
  1904.  bge.s .znoneg
  1905.  neg.w d2
  1906. .znoneg:
  1907.  cmp.w d1,d2
  1908.  ble.s .checkx
  1909.  sub.w (a3),d2
  1910.  cmp.w (a2,d3.w*8),d2
  1911.  bgt checkcol
  1912.  st hitwall
  1913.  bra checkedallcol
  1914. .checkx:
  1915.  sub.w (a3),d1
  1916.  cmp.w (a2,d3.w*8),d1
  1917.  bgt checkcol
  1918.  
  1919.  move.w (a1,d0.w*8),d1
  1920.  move.w 4(a1,d0.w*8),d2
  1921.  move.w d1,d6
  1922.  move.w d2,d7
  1923.  sub.w newx,d6
  1924.  sub.w newz,d7
  1925.  muls d6,d6
  1926.  muls d7,d7
  1927.  add.l d6,d7
  1928.  sub.w oldx,d1
  1929.  sub.w oldz,d2
  1930.  muls d1,d1
  1931.  muls d2,d2
  1932.  add.l d1,d2
  1933.  cmp.l d2,d7
  1934.  bgt checkcol
  1935.  
  1936.  st hitwall
  1937.  bra checkedallcol
  1938.  
  1939. ; bra checkcol
  1940.  
  1941. checkedallcol:
  1942.  rts
  1943.  
  1944. ColBoxTable:
  1945.  
  1946. ; red scurrying alien
  1947.  dc.w 40,60,120,0
  1948. ; Medipack
  1949.  dc.w 40,20,40,0
  1950. ; Bullet
  1951.  dc.w 40,20,40,0
  1952. ; Gun
  1953.  dc.w 40,20,40,0
  1954. ; Key
  1955.  dc.w 40,20,40,0
  1956. ; PLayer1
  1957.  dc.w 40,40,80,0
  1958. ;Robot
  1959.  dc.w 40,50,100,0
  1960. ;?
  1961.  dc.w 40,20,40,0
  1962. ; Flying Nasty
  1963.  dc.w 80,60,120,0
  1964. ; Ammo
  1965.  dc.w 40,20,40,0
  1966. ; Barrel
  1967.  dc.w 40,30,60,0
  1968. ;PlAYER2
  1969.  dc.w 40,40,80,0
  1970. ; Mutant Marine
  1971.  dc.w 40,40,80,0
  1972. ; worm
  1973.  dc.w 80,60,120,0
  1974. ; huge red thing
  1975.  dc.w 160,100,200,0
  1976. ; small red thing
  1977.  dc.w 80,50,100,0
  1978. ; tree
  1979.  dc.w 80,60,120,0
  1980. ; eyeball
  1981.  dc.w 40,30,60,0
  1982. ; Tough Marine
  1983.  dc.w 40,40,80,0
  1984. ; ShotGun Marine
  1985.  dc.w 40,40,80,0
  1986.  
  1987. FromZone: dc.w 0
  1988. OKTEL: dc.w 0
  1989. floortemp: dc.l 0
  1990.  
  1991. CheckTeleport:
  1992.  clr.b OKTEL
  1993.  move.w FromZone,d0
  1994.  move.l ZoneAdds,a2
  1995.  move.l (a2,d0.w*4),a2
  1996.  add.l LEVELDATA,a2
  1997.  tst.w ToTelZone(a2)
  1998.  bge.s ITSATEL
  1999.  rts
  2000.  
  2001. ITSATEL:
  2002.  move.l ToZoneFloor(a2),floortemp
  2003.  move.w ToTelZone(a2),d0
  2004.  move.l ZoneAdds,a3
  2005.  move.l (a3,d0.w*4),a3
  2006.  add.l LEVELDATA,a3
  2007.  move.l ToZoneFloor(a3),d0
  2008.  sub.l floortemp,d0
  2009.  move.l d0,floortemp
  2010.  add.l d0,newy 
  2011.  move.w ToTelX(a2),newx
  2012.  move.w ToTelZ(a2),newz
  2013.  move.l #%1111111111111111111,CollideFlags
  2014.  movem.l a0/a1/a2,-(a7)
  2015.  bsr Collision
  2016.  movem.l (a7)+,a0/a1/a2
  2017.  
  2018.  move.l floortemp,d0
  2019.  sub.l d0,newy
  2020.  
  2021.  tst.b hitwall
  2022.  seq OKTEL
  2023.  beq.s .teleport
  2024.  rts
  2025. .teleport:
  2026.  move.w ToTelZone(a2),d0
  2027.  move.l ZoneAdds,a2
  2028.  move.l (a2,d0.w*4),a2
  2029.  add.l LEVELDATA,a2
  2030.  move.l a2,objroom
  2031.  
  2032.  rts
  2033.  
  2034. FindCloseRoom:
  2035.  ; d0 is distance.
  2036.  
  2037.  move.w 4(a0),d1
  2038.  ext.l d1
  2039.  asl.l #7,d1
  2040.  move.l d1,oldy
  2041.  move.l d1,newy
  2042.  
  2043.  move.w (a0),d1
  2044.  move.l ObjectPoints,a1
  2045.  lea (a1,d1.w*8),a1
  2046.  move.w (a1),oldx 
  2047.  move.w 4(a1),oldz
  2048.  
  2049.  move.w 12(a0),d2
  2050.  move.l ZoneAdds,a5
  2051.  move.l (a5,d2.w*4),d2
  2052.  add.l LEVELDATA,d2
  2053.  move.l d2,objroom
  2054.  
  2055.  move.w THISPLRxoff,newx
  2056.  move.w THISPLRzoff,newz
  2057.  move.w d0,speed
  2058.  movem.l a0/a1,-(a7)
  2059.  jsr HeadTowards
  2060.  movem.l (a7)+,a0/a1
  2061.  
  2062.  move.w newx,d0
  2063.  sub.w oldx,d0
  2064.  move.w oldz,d1
  2065.  sub.w newz,d1
  2066.  
  2067.  move.w d1,xd
  2068.  move.w d0,zd
  2069.  
  2070.  move.l #100000,StepUpVal
  2071.  move.l #100000,StepDownVal
  2072.  move.w #0,thingheight
  2073.  
  2074.  st exitfirst
  2075.  
  2076.  add.w oldx,d1
  2077.  add.w oldz,d0
  2078.  move.w d1,newx
  2079.  move.w d0,newz
  2080.  movem.l d0-d7/a0-a6,-(a7)
  2081.  jsr MoveObject
  2082.  movem.l (a7)+,d0-d7/a0-a6
  2083.  
  2084.  move.l #RoomPath,a2
  2085.  move.l #possclose,a3
  2086.  move.w 12(a0),(a3)+
  2087.  
  2088. putinmore:
  2089.  move.w (a2)+,(a3)+
  2090.  bge.s putinmore
  2091.  subq #2,a3
  2092.  
  2093.  move.w oldx,d0
  2094.  sub.w xd,d0
  2095.  move.w oldz,d1
  2096.  sub.w zd,d1
  2097.  move.w d0,newx
  2098.  move.w d1,newz    
  2099.  
  2100.  movem.l d0-d7/a0-a6,-(a7)
  2101.  jsr MoveObject
  2102.  movem.l (a7)+,d0-d7/a0-a6
  2103.  
  2104.  move.l #RoomPath,a2
  2105.  
  2106. putinmore2:
  2107.  move.w (a2)+,d0
  2108.  move.w d0,(a3)+
  2109.  tst.w d0
  2110.  bge.s putinmore2
  2111.  
  2112. ; ok a3 points at list of rooms passed through.
  2113.  move.w #-1,(a3)+
  2114.  
  2115.  
  2116.  move.w 12(a0),d7
  2117.  
  2118.  move.l endoflist,a3
  2119. FINDCLOSELOOP:
  2120.  move.l #possclose,a2
  2121.  move.w -(a3),d0
  2122.  blt foundclose
  2123.  
  2124. findinner
  2125.  move.w (a2)+,d1
  2126.  blt.s outin
  2127.  cmp.w d0,d1
  2128.  bne.s findinner
  2129.  move.w d0,d7
  2130. outin:
  2131.  
  2132.  bra.s FINDCLOSELOOP
  2133.  
  2134. foundclose:
  2135.  
  2136.  move.w d7,GraphicRoom(a0)
  2137.  
  2138.  rts
  2139.  
  2140. xd: dc.w 0
  2141. zd: dc.w 0
  2142.  
  2143. possclose:
  2144.  ds.w 100